<?php

namespace app\admin\model\article;


use think\Model;

/**
 * 标签模型
 * Class Article
 * @package app\store\model
 */
class Article extends Model
{
    protected $name = 'love_expire';
    protected $append = ['show_views'];
    /**
     * 标签详情
     */
    public static function detail($article_id){
        return self::get($article_id);
    }

    /**
     * 获取标签列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList(){
        return $this
            ->order([ 'create_time' => 'desc'])
            ->paginate(15, false, [
                'query' => request()->request()
            ]);

    }

    /**
     * 新增记录
     */
    public function add($data){
        if (empty($data['name'])) {
            $this->error = '请输入名称';
            return false;
        }
        if (empty($data['expiretime'])) {
            $this->error = '请输入保护时间';
            return false;
        }
        $data['create_time']=time();
        return $this->allowField(true)->save($data);
    }

    /**
     * 更新记录
     * @param $data
     * @return bool|int
     */
    public function edit($data){
        if (empty($data['name'])) {
            $this->error = '请输入名称';
            return false;
        }
        if (empty($data['expiretime'])) {
            $this->error = '请输入保护时间';
            return false;
        }
        $data['update_time']=time();
        return $this->allowField(true)->save($data) !== false;
    }

    /**
     * 软删除
     */
    public function setDelete($status){
        return $this->save(['is_delete' => $status]);
    }


}